package com.edu.marker.utils;

import android.graphics.Point;
import android.graphics.Region;
import android.util.Log;


public class CalculateUtil {
	private static final String TAG = "CalculateUtil";

	/**
	 * 判断point点是否在路径附近
	 * @param x1
	 * @param y1
	 * @param x2
	 * @param y2
	 * @param pointX
	 * @param pointY
	 * @return
	 */
	public static boolean isPointNearRect(int left,int top,int right,int bottom,int pointX,int pointY){
		Log.e(TAG, " left = "+left+" top = "+top +"  right = "+right+"  bottom = "+bottom);
		Region region = new Region(left, top, right, bottom);
		boolean result = false;
		if(region.contains(pointX,pointY)){
			result = true;
		}else{
			result = false;
		}
		Log.e(TAG, "isPointNearRect = "+result);
		return result;
	}
	
	/**
	 * 
	 * @param realHeight 实际的图片高度
	 * @param realWidth 实际的图片宽度
	 * @param realPointX 实际的图片中的矩形坐标x
	 * @param realPointY 实际的图片中的矩形坐标y
	 * @param currHeight 当前用于显示的图像区域高度
	 * @param currWidth 当前用于显示的图像区域宽度
	 * @param currPointLeft 当前用于显示的图像区域左上角坐标x
	 * @param currPointTop 当前用于显示的图像区域左上角坐标y
	 * @return 返回实际矩形显示的坐标
	 */
	public static Point getRealPoint(int realHeight,int realWidth,int realPointX,int realPointY,
			int currHeight,int currWidth,int currPointLeft,int currPointTop){
		//判断是高小于宽还是宽小于高
//		if(true){
//			//图片高小于宽
//			int h = realHeight*currWidth/realWidth;//显示时的图片高度
//			int x = realPointX*currWidth/realWidth;//显示时的矩形相对坐标x
//			int y = realPointY*h/realHeight;//显示时的矩形相对坐标y
//			
//			//计算实际显示时的左上角坐标，高小于宽时，只需计算y坐标
//			int left = currPointLeft;
//			int top = currPointTop + (currHeight - h)/2;
//		}else{
		//图片宽小于高
			int w = realWidth*currHeight/realHeight;//显示时的图片宽度
			int x = w*realPointX/realWidth;//显示时的矩形相对坐标x
			int y = realPointY*currHeight/realHeight;//显示时的矩形相对坐标y
			
			//计算实际显示时的左上角坐标，宽小于高时，只需计算x坐标
			int left = currPointLeft + (currWidth - w)/2;
			int top = currPointTop;
//		}
		
		
		
		return new Point(x+left, y+top);
//		return null;
	}
}
